package com.happe.foodeasy.winter.conf.parser;

import com.happe.foodeasy.winter.helper.ConfigurationFilesParserHelper;
import org.springframework.stereotype.Component;

import java.util.concurrent.Callable;

/**
 * This method is used to parse properties file for database type.
 * Created by wubin on 2016-05-19.
 */
@Component
public class DatabaseTypePropertiesParser extends DatabaseTypeParser {

    private static final String PROPERTIES_FILE_POSTFIX = ".type.properties";
    private String databaseTypePropertiesName;
    @Override
    protected Callable<DatabaseTypeMapParseResult> requireTaskCallable() {
        return new databasePropertiesCallable();
    }

    private class databasePropertiesCallable extends PropertiesFileParseTaskCallable<DatabaseTypeMapParseResult> {
        @Override
        protected Class<DatabaseTypeMapParseResult> retrieveParseResultType() {
            return DatabaseTypeMapParseResult.class;
        }

        @Override
        protected String retrieveParseFilePath() {
            return ConfigurationFilesParserHelper.getPathInRootClassPath(databaseTypePropertiesName);
        }
    }

    @Override
    public void setDatabaseType(String databaseType) {
        this.databaseTypePropertiesName = databaseType + PROPERTIES_FILE_POSTFIX;
    }
}
